import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:oli/pages/main/home/statisitc/view.dart';
import 'package:oli/widget/RecordListWidget.dart';
import 'package:oli/router/MainRoutePath.dart';

import 'logic.dart';

class HomePage extends StatelessWidget {
  const HomePage({super.key});
  @override
  Widget build(BuildContext context) {
    final logic = Get.find<HomeLogic>();
    final state = logic.state;
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Colors.orange.shade300,
        elevation: 4,
        centerTitle: true,
        title: ShaderMask(
          shaderCallback: (Rect bounds) {
            return LinearGradient(
              colors: [
                Colors.red,
                Colors.orange,
                Colors.yellow,
                Colors.green,
                Colors.blue,
                Colors.indigo,
                Colors.purple,
              ],
              begin: Alignment.topLeft,
              end: Alignment.bottomRight,
            ).createShader(bounds);
          },
          child: Obx(
            () => Text(
              state.dynamicTitle.value,
              style: const TextStyle(
                fontSize: 18,
                fontWeight: FontWeight.bold,
                color: Colors.white,
              ),
            ),
          ),
        ),
        actions: [
          Padding(
            padding: const EdgeInsets.only(right: 16),
            child: IconButton(
              icon: const Icon(Icons.add, size: 36, color: Colors.white),
              splashRadius: 24,
              onPressed: () {
                Get.toNamed(MainRoutePath.addRecord);
              },
              splashColor: Colors.white.withOpacity(0.3),
              highlightColor: Colors.white.withOpacity(0.2),
            ),
          ),
        ],
      ),
      body: Container(
        color: Colors.white,
        child: Column(
          children: [
            const StatisticPage(),
            RecordListWidget(records: state.records),
          ],
        ),
      ),
    );
  }
}
